import CryptoJS from 'crypto-js';
import moment from 'moment';
const KEY = CryptoJS.enc.Utf8.parse('/45694d696b6f/eimiko'); //十六位十六进制数作为秘钥
// 加密
export function aesEncode(raw: any) {
  const iv = CryptoJS.enc.Utf8.parse(moment().format('~YYYY~MM~DD~HH~~'));
  const word = JSON.stringify(raw);
  const srcs = CryptoJS.enc.Utf8.parse(word);
  const encrypted = CryptoJS.AES.encrypt(srcs, KEY, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
    padding: CryptoJS.pad.Pkcs7,
  });
  return encrypted.ciphertext.toString().toUpperCase();
}
